home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tcl7.4 / tclPort.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-11  |  6.4 KB  |  304 lines

  1. /*
  2.  * tclPort.h --
  3.  *
  4.  *    This header file handles porting issues that occur because
  5.  *    of differences between systems.  It reads in UNIX-related
  6.  *    header files and sets up UNIX-related macros for Tcl's UNIX
  7.  *    core.  It should be the only file that contains #ifdefs to
  8.  *    handle different flavors of UNIX.  This file sets up the
  9.  *    union of all UNIX-related things needed by any of the Tcl
  10.  *    core files.  This file depends on configuration #defines such
  11.  *    as NO_DIRENT_H that are set up by the "configure" script.
  12.  *
  13.  *    Much of the material in this file was originally contributed
  14.  *    by Karl Lehenbauer, Mark Diekhans and Peter da Silva.
  15.  *
  16.  * Copyright (c) 1991-1994 The Regents of the University of California.
  17.  * Copyright (c) 1994 Sun Microsystems, Inc.
  18.  *
  19.  * See the file "license.terms" for information on usage and redistribution
  20.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  21.  *
  22.  * @(#) tclPort.h 1.6 95/05/11 10:46:38
  23.  */
  24.  
  25. #ifndef _TCLPORT
  26. #define _TCLPORT
  27.  
  28. #include <errno.h>
  29. #include <fcntl.h>
  30. #include <pwd.h>
  31. #include <signal.h>
  32. #include <sys/param.h>
  33. #include <sys/types.h>
  34. #ifdef USE_DIRENT2_H
  35. #   include "compat/dirent2.h"
  36. #else
  37. #   ifdef NO_DIRENT_H
  38. #    include "compat/dirent.h"
  39. #   else
  40. #    include <dirent.h>
  41. #   endif
  42. #endif
  43. #include <sys/file.h>
  44. #include <sys/stat.h>
  45. #ifndef NO_SYS_TIME_H
  46. #   include <sys/time.h>
  47. #else
  48. #   include <time.h>
  49. #endif
  50. #ifndef NO_SYS_WAIT_H
  51. #   include <sys/wait.h>
  52. #endif
  53. #ifdef HAVE_UNISTD_H
  54. #   include <unistd.h>
  55. #else
  56. #   include "compat/unistd.h"
  57. #endif
  58.  
  59. /*
  60.  * Not all systems declare the errno variable in errno.h. so this
  61.  * file does it explicitly.  The list of system error messages also
  62.  * isn't generally declared in a header file anywhere.
  63.  */
  64.  
  65. extern int errno;
  66.  
  67. /*
  68.  * The type of the status returned by wait varies from UNIX system
  69.  * to UNIX system.  The macro below defines it:
  70.  */
  71.  
  72. #ifdef AIX
  73. #   define WAIT_STATUS_TYPE pid_t
  74. #else
  75. #ifndef NO_UNION_WAIT
  76. #   define WAIT_STATUS_TYPE union wait
  77. #else
  78. #   define WAIT_STATUS_TYPE int
  79. #endif
  80. #endif
  81.  
  82. /*
  83.  * Supply definitions for macros to query wait status, if not already
  84.  * defined in header files above.
  85.  */
  86.  
  87. #ifndef WIFEXITED
  88. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  89. #endif
  90.  
  91. #ifndef WEXITSTATUS
  92. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  93. #endif
  94.  
  95. #ifndef WIFSIGNALED
  96. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  97. #endif
  98.  
  99. #ifndef WTERMSIG
  100. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  101. #endif
  102.  
  103. #ifndef WIFSTOPPED
  104. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  105. #endif
  106.  
  107. #ifndef WSTOPSIG
  108. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  109. #endif
  110.  
  111. /*
  112.  * Define constants for waitpid() system call if they aren't defined
  113.  * by a system header file.
  114.  */
  115.  
  116. #ifndef WNOHANG
  117. #   define WNOHANG 1
  118. #endif
  119. #ifndef WUNTRACED
  120. #   define WUNTRACED 2
  121. #endif
  122.  
  123. /*
  124.  * Supply macros for seek offsets, if they're not already provided by
  125.  * an include file.
  126.  */
  127.  
  128. #ifndef SEEK_SET
  129. #   define SEEK_SET 0
  130. #endif
  131.  
  132. #ifndef SEEK_CUR
  133. #   define SEEK_CUR 1
  134. #endif
  135.  
  136. #ifndef SEEK_END
  137. #   define SEEK_END 2
  138. #endif
  139.  
  140. /*
  141.  * The stuff below is needed by the "time" command.  If this
  142.  * system has no gettimeofday call, then must use times and the
  143.  * CLK_TCK #define (from sys/param.h) to compute elapsed time.
  144.  * Unfortunately, some systems only have HZ and no CLK_TCK, and
  145.  * some might not even have HZ.
  146.  */
  147.  
  148. #ifdef NO_GETTOD
  149. #   include <sys/times.h>
  150. #   include <sys/param.h>
  151. #   ifndef CLK_TCK
  152. #       ifdef HZ
  153. #           define CLK_TCK HZ
  154. #       else
  155. #           define CLK_TCK 60
  156. #       endif
  157. #   endif
  158. #else
  159. #   ifdef HAVE_BSDGETTIMEOFDAY
  160. #    define gettimeofday BSDgettimeofday
  161. #   endif
  162. #endif
  163.  
  164. #ifdef GETTOD_NOT_DECLARED
  165. EXTERN int        gettimeofday _ANSI_ARGS_((struct timeval *tp,
  166.                 struct timezone *tzp));
  167. #endif
  168.  
  169. /*
  170.  * Define access mode constants if they aren't already defined.
  171.  */
  172.  
  173. #ifndef F_OK
  174. #    define F_OK 00
  175. #endif
  176. #ifndef X_OK
  177. #    define X_OK 01
  178. #endif
  179. #ifndef W_OK
  180. #    define W_OK 02
  181. #endif
  182. #ifndef R_OK
  183. #    define R_OK 04
  184. #endif
  185.  
  186. /*
  187.  * Define FD_CLOEEXEC (the close-on-exec flag bit) if it isn't
  188.  * already defined.
  189.  */
  190.  
  191. #ifndef FD_CLOEXEC
  192. #   define FD_CLOEXEC 1
  193. #endif
  194.  
  195. /*
  196.  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
  197.  * define "lstat" to use "stat" instead.
  198.  */
  199.  
  200. #ifndef S_IFLNK
  201. #   define lstat stat
  202. #endif
  203.  
  204. /*
  205.  * Define macros to query file type bits, if they're not already
  206.  * defined.
  207.  */
  208.  
  209. #ifndef S_ISREG
  210. #   ifdef S_IFREG
  211. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  212. #   else
  213. #       define S_ISREG(m) 0
  214. #   endif
  215. # endif
  216. #ifndef S_ISDIR
  217. #   ifdef S_IFDIR
  218. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  219. #   else
  220. #       define S_ISDIR(m) 0
  221. #   endif
  222. # endif
  223. #ifndef S_ISCHR
  224. #   ifdef S_IFCHR
  225. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  226. #   else
  227. #       define S_ISCHR(m) 0
  228. #   endif
  229. # endif
  230. #ifndef S_ISBLK
  231. #   ifdef S_IFBLK
  232. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  233. #   else
  234. #       define S_ISBLK(m) 0
  235. #   endif
  236. # endif
  237. #ifndef S_ISFIFO
  238. #   ifdef S_IFIFO
  239. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  240. #   else
  241. #       define S_ISFIFO(m) 0
  242. #   endif
  243. # endif
  244. #ifndef S_ISLNK
  245. #   ifdef S_IFLNK
  246. #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  247. #   else
  248. #       define S_ISLNK(m) 0
  249. #   endif
  250. # endif
  251. #ifndef S_ISSOCK
  252. #   ifdef S_IFSOCK
  253. #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  254. #   else
  255. #       define S_ISSOCK(m) 0
  256. #   endif
  257. # endif
  258.  
  259. /*
  260.  * Make sure that MAXPATHLEN is defined.
  261.  */
  262.  
  263. #ifndef MAXPATHLEN
  264. #   ifdef PATH_MAX
  265. #       define MAXPATHLEN PATH_MAX
  266. #   else
  267. #       define MAXPATHLEN 2048
  268. #   endif
  269. #endif
  270.  
  271. /*
  272.  * Make sure that L_tmpnam is defined.
  273.  */
  274.  
  275. #ifndef L_tmpnam
  276. #   define L_tmpnam 100
  277. #endif
  278.  
  279. /*
  280.  * Substitute Tcl's own versions for several system calls.  The
  281.  * Tcl versions retry automatically if interrupted by signals.
  282.  * (see tclUnixUtil.c).
  283.  */
  284.  
  285. #define open(a,b,c) TclOpen(a,b,c)
  286. #define read(a,b,c) TclRead(a,b,c)
  287. #define waitpid(a,b,c) TclWaitpid(a,b,c)
  288. #define write(a,b,c) TclWrite(a,b,c)
  289. EXTERN int    TclOpen _ANSI_ARGS_((char *path, int oflag, int mode));
  290. EXTERN int    TclRead _ANSI_ARGS_((int fd, VOID *buf, size_t numBytes));
  291. EXTERN int    TclWaitpid _ANSI_ARGS_((pid_t pid, int *statPtr, int options));
  292. EXTERN int    TclWrite _ANSI_ARGS_((int fd, VOID *buf, size_t numBytes));
  293.  
  294. /*
  295.  * Variables provided by the C library:
  296.  */
  297.  
  298. #if defined(_sgi) || defined(__sgi)
  299. #define environ _environ
  300. #endif
  301. extern char **environ;
  302.  
  303. #endif /* _TCLPORT */
  304.